package dolf.objects.weapons.Saw;

import java.awt.Graphics2D;
import java.awt.Image;
import javax.swing.ImageIcon;

import dolf.game.Level;
import dolf.game.Player;
import dolf.objects.*;
import dolf.objects.weapons.*;
import dolf.window.SystemMessagesHandler;

public class Saw extends CircleObject implements Weapon, java.io.Serializable {
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	public static final int Price = 125;
	public static final String Name = SystemMessagesHandler.getInstance().getMessages("dolf.objects.weapons.Saw.lang.lang").getString("name");
	public static final String WeaponType = SystemMessagesHandler.getInstance().getMessages("dolf.objects.weapons.Saw.lang.lang").getString("type");
	public static final String Description = SystemMessagesHandler.getInstance().getMessages("dolf.objects.weapons.Saw.lang.lang").getString("description");
	public static final javax.swing.ImageIcon Icon = ImageStore.getInstance().getIcon("dolf/objects/weapons/Saw/gfx/icon.png");
	
	private int currImageIndex = 0;
	private Player pl;
	private boolean inititalized = false;
	
	transient private java.util.Vector<Image> imgVec;
	
	
	public Saw(){
		super(null,11,false);
		this.setCollitabe(false);
		loadRotation();
		
	}
	//load images of rotating saw blade
	private void loadRotation() {
		imgVec = new java.util.Vector<Image>();
		for (int i = 0; i <= 5; i++) {
			Image img = ImageStore.getInstance().getImage("dolf/objects/weapons/Saw/gfx/animation"+i+".png");
			img = img.getScaledInstance(2*this.getRadius(), 2*this.getRadius(), Image.SCALE_SMOOTH);
			imgVec.add(img);
		}
	}
	
	public void initialize(Player _pl){
		if(this.inititalized){
			return;
		}
		this.inititalized = true;
		this.pl = _pl;
		this.pl.setWeaponState();
		Level.getInstance().registerObject(this);
	}
	
	public void deInitialize(){
		Level.getInstance().removeObject(this);
		this.pl = null;
		this.inititalized = false;
	}
	
	public void execute() {
		WorldObject o;
		Ball obj;
		for(int i = 0; i < Level.getInstance().getPlayers().size(); i++){
			if((o=Level.getInstance().getPlayers().get(i).getBall()) != pl.getBall()){
				obj = (Ball) o;
				if(this.kollCircle(obj)>=0 && obj.isVisible()){
					obj.getPlayer().removeHP(2);
					this.pl.addDamage(2);
				}
			}
		}
	}
	
	
	public void paint(Graphics2D g){
		if (imgVec == null) {
			loadRotation();
		}

		g.drawImage(imgVec.get(currImageIndex), this.getPosition().getIntX()-this.getRadius(), this.getPosition().getIntY()-this.getRadius(), null);
		currImageIndex = ((currImageIndex + 1) % 3);
	}

	public boolean newMotion(WorldObject object){
		/*if(object != b)
			System.out.println("nicht b");
		System.out.println("juhu");*/
		return true;
	}	
	public ImageIcon getIcon() {
		return Icon;//ImageStore.getInstance().getIcon("dolf/objects/weapons/Saw/gfx/icon.png");	
	}

	public String getName() {
		return Name;
		/*if (messages == null) loadProperties();
		return messages.getString("name");*/
	}
	
	public String getDescription() {
		return Description;
		/*if (messages == null) loadProperties();
		return messages.getString("description");*/
	}
	public String getType(){
		return WeaponType;
	}
	public int getPrice() {
		return Price;
	}
	public void remove(){
		Level.getInstance().removeObject(this);
		pl.getBall().getPlayer().removeWeapon(this);
		pl.setAktWeapon(null);
	}
	public Point getPosition(){
		return pl.getBall().getPosition().getCopy();
	}
	public Vector getMotion(){
		return pl.getBall().getMotion().getCopy();
	}
	
	public Player getPlayer(){
		return this.pl;
	}
	public double getState(){
		return 0;
	}
}
